import React, { useReducer } from 'react';

function ReducerDome(){
    const[count,dispatch]=useReducer((state,action)=>{
        switch(action){
            case  'add':
                return  state+1;
            case 'sub':
                return state-1;
        } 
    },0)
    return(
        <div>
        <h2>你得到的数是{count}</h2>
        <button onClick={()=>dispatch('add')}>add</button>
        <button onClick={()=>dispatch('sub')}>sub</button>
        </div>
    )
}
export default  ReducerDome;